// pages/index/referral/referral.js
var a = function(a) {
    return a && a.__esModule ? a : {
      default: a
    };
  }(require("../../../../utils/toot.js")),
  t = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Height: '',
    name: 1,
    yesAddNo: false,
    xx: false,
    perfect: 0,
    perfect1: 0,
    submission: {
      doctor: '请选择医生',
      information: {
        userId: 1,
        userIcon: '/assets/images / head.png',
        name: '小明',
        nmGender: '女',
        age: 30,
        remarkName: '小红',
        disease: '感冒',
        img: []
      }
    }
  },
  agree: function(e) {
    console.log(e)
  },
  choice: function(e) {
    let that = this;
    that.setData({
      name: e.target.id
    })
    let a = that.data.name;
    if (a == 1) {
      that.setData({
        'submission.doctor': '请选择医生'
      })
    }
    if (a == 2) {
      that.setData({
        'submission.doctor': '请选择医院及科室'
      })
    }
    if (a == 3) {
      that.setData({
        'submission.doctor': '请选择推荐'
      })
    }
  },
  send: function() {
    let that = this;
    let a = that.data.yesAddNo;
    if (a == false) {
      that.setData({
        yesAddNo: true
      })
    } else {
      that.setData({
        yesAddNo: false
      })
    }
  },
  OK: function(e) {
    var that = this
    var yesAddNo = that.data.yesAddNo
    if (yesAddNo == true) {
      var sed = 1
    } else {
      var sed = 0
    }
    var mzid = that.data.zid
    var zid = e.currentTarget.dataset.zid
    var my_id = e.currentTarget.dataset.uid
    var phone = e.currentTarget.dataset.phone
    if (phone == undefined || my_id == undefined || zid == undefined) {
      wx.showToast({
        title: '请完善医生信息或患者信息',
        icon: 'none',
        duration: 2000
      })
    } else {
      //1发送短信通知患者转诊
      //2更改患者签约医生
      t.util.request({
        'url': 'entry/wxapp/Saveqianyu',
        data: {
          phone: phone,
          zid: zid,
          my_id: my_id,
          sed: sed,
          mzid: mzid
        },
        success: function(res) {
          console.log(res)
          if (res.data == 1) {
            wx.showToast({
              title: '转诊成功',
              icon: 'none',
              duration: 2000,
              success: function(res) {
                setTimeout(function() {
                  wx.navigateBack({
                    delta: 1
                  })
                }, 2000)
              }
            })
          } else {
            wx.showToast({
              title: '操作有误,患者已签约您',
              icon: 'none',
              duration: 2000,
            })
          }
        }
      })

    }
  },
  // 选择医生科室
  choiceObject: function() {
    let that = this;
    let a = that.data.name;

    if (a == 1) {
      wx.navigateTo({
        url: "/hyb_yl/backstageMethod/pages/doctor/doctor"
      });
    } else {
      wx.navigateTo({
        url: "/hyb_yl/backstageMethod/pages/yiyuanlist/yiyuanlist"
      });
    }
  },
  lookFor: function(e) {
    var that = this
    var hzinfo = that.data.hzinfo;
    wx.navigateTo({
      url: "/hyb_yl/backstageMethod/pages/patient/patient?hzinfo=" + hzinfo
    });
  },
  personal: function(e) {
    var huzopenid = e.currentTarget.dataset.huzopenid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/xinzengyiliao/xinzengyiliao?huzopenid=' + huzopenid + '&fuwu_name=' + '患者病程'
    });
  },
  addImg: function(e) {
    console.log(e)
    let d = e.target.dataset.index;
    let a = 'submission.information.img';
    let b = this.data.submission.information.img;
    let c = 'submission.information.img[' + d + ']';
    let f = '/assets/images/tianjiatu.jpg';
    var that = this;
    if (b.length != 9 && d != b.length - 1) {
      wx.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'],
        sourceType: ['album', 'camera'],
        success(res) {
          // tempFilePath可以作为img标签的src属性显示图片
          let tempFilePaths = res.tempFilePaths;
          b[d] = tempFilePaths[0];
          that.setData({
            [c]: tempFilePaths
          })
          if (b.length > 9) {
            b.splice(b.length - 1);
            wx.showToast({
              title: '最多上传9张图片',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    } else {
      if (b.length != 9) {
        wx.chooseImage({
          count: 9,
          sizeType: ['original', 'compressed'],
          sourceType: ['album', 'camera'],
          success(res) {
            // tempFilePath可以作为img标签的src属性显示图片
            let tempFilePaths = res.tempFilePaths;
            for (let i = 0; i < tempFilePaths.length; i++) {
              b.unshift(tempFilePaths[i])
            }
            if (b.length > 9) {
              b.splice(9);
              wx.showToast({
                title: '最多上传9张图片',
                icon: 'none',
                duration: 2000
              })
            }
            that.setData({
              [a]: b
            })
          }
        })
      } else {
        wx.chooseImage({
          count: 9,
          sizeType: ['original', 'compressed'],
          sourceType: ['album', 'camera'],
          success(res) {
            // tempFilePath可以作为img标签的src属性显示图片
            let tempFilePaths = res.tempFilePaths;
            b[d] = tempFilePaths[0];
            that.setData({
              [a]: b
            })
            if (b.length > 9) {
              b.splice(b.length - 1);
              wx.showToast({
                title: '最多上传9张图片',
                icon: 'none',
                duration: 2000
              })
            }
          }
        })
      }
    }
  },
  delete: function(e) {
    console.log(e)
    let a = e.currentTarget.dataset.index;
    let b = this.data.submission.information.img;
    let c = 'submission.information.img';
    b.splice(a, 1);
    this.setData({
      [c]: b
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var zid = options.zid
    t.util.request({
      'url': 'entry/wxapp/Orderguanqianyu',
      data: {
        zid: zid
      },
      success: function(res) {
        console.log(res)
        var hzinfo = JSON.stringify(res.data.data)
        that.setData({
          hzinfo: hzinfo
        })
      }
    })
    that.setData({ zid: zid})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    let that = this;
    let a = ''
    wx.getSystemInfo({
      success: function(res) {
        a = res.windowHeight;
      },
    })
    that.setData({
      Height: a
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];
    if (currPage.data.daninfo) {
      that.setData({
        daninfo: currPage.data.daninfo,
        perfect: 1,
        perfect1: 0
      })

      console.log(currPage.data.daninfo)
    }
    if (currPage.data.zhuanjia) {
      that.setData({
        zhuanjia: currPage.data.zhuanjia,
        perfect1: 'doc',
        perfect: 0
      })
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})